RegisterCallback
Registers a function that the KINGSTAR Subsystem will call every cycle when new data comes in.
Syntax
KsError RegisterCallback(
AppCallback callback,
PVOID context
);
Parameters
callback: pointer to the callback function that will be called every cycle. See the AppCallback type.
context: pointer passed to the callback function if you need it.
Return value
If the function succeeds, it returns errNoError, otherwise an error code. For more information about the error code, see the KsError list.
Remarks
- Registering a callback is optional. You can have your own cyclic thread in your application.
- RegisterCallback can be used only in RT interface, because it is a real-time functionality. Calling it in other interfaces will get an
errWrongEnvironmenterror.
Usable EtherCAT states
ecatOP
Example
Copy
/*
* Assume that there is already a callback function in namespace userApp:
* namespace userApp
* {
* int callBack(PVOID Context)
{
* return 0;
* }
* }
*
* You can pass the function pointer as an argument:
*/
AppCallback callBack = userApp::callBack;
nRet = RegisterCallback(callBack, NULL);
/*
* Or you can decay a lambda function to a function pointer (C++11):
*/
nRet = RegisterCallback([](PVOID Context){ return 0; }, NULL);
Requirements
| RT | Win32 | |
|---|---|---|
| Minimum supported version | 4.0 | 4.0 |
| Header | ksapi.h | ksapi.h |
| Library | KsApi_Rtss.lib | KsApi.lib |
See also